<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md15">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-card">
                                <div class="layui-card-header">资源管理</div>
                                <br>
                                <form class="layui-row layui-form " style="display: flex;flex-direction: row" action="">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">筛选</label>
                                        <div class="layui-input-inline">
                                            <select name="cs" id="cs" lay-filter="cs">
                                                <option value="" selected="">请选择第几册</option>
                                                <option value="0">第一册</option>
                                                <option value="1">第二册</option>
                                                <option value="2">第三册</option>
                                                <option value="3">第四册</option>
                                                <option value="4">第五册</option>
                                                <option value="5">第六册</option>
                                            </select>
                                        </div>
                                    </div>
                                    <a class="layui-btn" id="fileScan"><span class="icon iconfont">&#xe685;</span>
                                        文件扫描
                                    </a>
                                </form>
                                <div class="layui-card-body">
                                    <table id="codeTable" lay-filter="codeTable"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>


<script>
    var startInter = api.reasource;
    var audio = "", cs = "";//初始化查询身份为教师,与当前的时间
    var type = /^[1-9]\d*$/;
    $(document).ready(function () {
        $("#search").click(function () {
            getStartUp();
        });
        cs = $("#cs").val();
        layui.use(['form', 'table', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate;
            //监听单选框的值
            form.on("radio(code)", function (data) {
                var code = data.value;
                getStartUp();
            });
            //监听筛选的选择框
            form.on("select(cs)", function (data) {
                cs = data.value;
                getStartUp();
            });
            form.render();
        });
        getStartUp();
        $("#fileScan").click(function () {
            scanFile();
        });
    });

    //文件扫描函数
    function scanFile() {
        $.ajax({
            url: 'api/resource.php',
            type: 'post',
            data: {'action': 'scanResource', type: 'm', Cs: cs},
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    layer.msg('扫描成功');

                } else {
                    layer.msg('扫描失败');
                }
            }
        });
    }

    function refresh() {
        getStartUp();
    }
    //获取启动次数的数据
    function getStartUp() {
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#codeTable'
                , url: startInter //数据接口
                , title: '资源列表数据'
                , page: true //开启分页
                , method: 'post'
                , totalRow: true
                , limit: 20
                , limits: [20, 40, 60, 100]
                , where: {
                    Cs: cs,
                    action: "listResource",
                }
                , cols: [[ //表头
                    {field: 'index', title: '序号', fixed: 'left', type: 'numbers', toolbar: "#tableId"}
                    , {field: 'rname', title: '资源名称', width: 150}
                    , {field: 'ver', title: '资源版本号', width: 150}
                    , {field: 'fname', title: '文件名称', width: 150,}
                    , {field: 'ctime', title: '创建时间', width: 150, toolbar: "#creatTime"}
                    , {field: "vol", title: '第几册', toolbar: "#uNit"}
                    , {field: 'url', title: '资源下载地址'}
                ]]
                , done: function (res, curr, count) {
                    if (res.count == 0) {
                        layer.msg("没有符合条件的数据哦");
                    }
                }

            });


        });

    }

</script>
<!--//册-->
<script type="text/html" id="uNit">
    <a style="color: #787878" class="layui-table-link">第{{changeUnit(d.vol)}}册</a>
</script>
<!--//有效时间-->
<script type="text/html" id="creatTime">
    <a style="color: #787878" class="layui-table-link">{{to_date(d.ctime)}}</a>
</script>
<!--//到期时间-->
<script type="text/html" id="actTime">
    {{#  if(d.acttime !=undefined){ }}
    <a style="color: #787878" class="layui-table-link">{{to_date(d.acttime)}}</a>
    {{#  } }}
</script>
<!--//更新时间-->
<script type="text/html" id="updateTime">
    {{#  if(d.updatetime !=undefined){ }}
    <a style="color: #787878" class="layui-table-link">{{to_date(d.updatetime)}}</a>
    {{#  } }}
</script>
<!--//是否过期-->
<script type="text/html" id="isExp">
    {{#  if(d.isexp =="1"){ }}
    <a style="color:#009688" class="layui-table-link">已过期</a>
    {{#  } }}
    {{#  if(d.isexp =="0"){ }}
    <a style="color: #787878" class="layui-table-link">未过期</a>
    {{#  } }}
</script>
<!--//是否激活-->
<script type="text/html" id="isAct">
    {{#  if(d.isact =="1"){ }}
    <a style="color:#009688" class="layui-table-link">已激活</a>
    {{#  } }}
    {{#  if(d.isact =="0"){ }}
    <a style="color: #787878" class="layui-table-link">未激活</a>
    {{#  } }}
</script>
<!--//是否印卡-->
<script type="text/html" id="isOut">
    {{#  if(d.isout =="1"){ }}
    <a style="color:#009688" class="layui-table-link">印卡</a>
    {{#  } }}
    {{#  if(d.isout =="0"){ }}
    <a style="color: #787878" class="layui-table-link">未印卡</a>
    {{#  } }}
</script>